package com.ruoyi.web.controller.data;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HdNasUser;
import com.ruoyi.system.service.IHdNasUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据用户管理Controller
 * 
 * @author luojiangwen
 * @date 2023-10-13
 */
@Controller
@RequestMapping("/auto_service/nasUser")
public class HdNasUserController extends BaseController
{
    private String prefix = "auto_service/nasUser";

    @Autowired
    private IHdNasUserService hdNasUserService;

    @RequiresPermissions("auto_service:nasUser:view")
    @GetMapping()
    public String nasUser()
    {
        return prefix + "/nasUser";
    }
    
    /**
     * 验证数据用户
     */
    @RequiresPermissions("auto_service:nasUser:export")
    @Log(title = "数据用户登录", businessType = BusinessType.GRANT)
    @PostMapping("/userLogin")
    @ResponseBody
    public AjaxResult userLogin(HdNasUser hdNasUser)
    {
    	System.out.println(hdNasUser);
        List<HdNasUser> list = hdNasUserService.selectHdNasUserList(hdNasUser);
        for(HdNasUser user : list) {
        	System.out.println(user);
        }
        if(list != null && !list.isEmpty()) {
        	return AjaxResult.success("登录成功");
        }
        return AjaxResult.error("登录失败");
    }
    
    /**
     * 查询数据用户管理列表
     */
    @RequiresPermissions("auto_service:nasUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HdNasUser hdNasUser)
    {
        startPage();
        List<HdNasUser> list = hdNasUserService.selectHdNasUserList(hdNasUser);
        return getDataTable(list);
    }

    /**
     * 导出数据用户管理列表
     */
    @RequiresPermissions("auto_service:nasUser:export")
    @Log(title = "数据用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HdNasUser hdNasUser)
    {
        List<HdNasUser> list = hdNasUserService.selectHdNasUserList(hdNasUser);
        ExcelUtil<HdNasUser> util = new ExcelUtil<HdNasUser>(HdNasUser.class);
        return util.exportExcel(list, "数据用户管理数据");
    }

    /**
     * 新增数据用户管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据用户管理
     */
    @RequiresPermissions("auto_service:nasUser:add")
    @Log(title = "数据用户管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HdNasUser hdNasUser)
    {
        return toAjax(hdNasUserService.insertHdNasUser(hdNasUser));
    }

    /**
     * 修改数据用户管理
     */
    @RequiresPermissions("auto_service:nasUser:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        HdNasUser hdNasUser = hdNasUserService.selectHdNasUserByUserId(userId);
        mmap.put("hdNasUser", hdNasUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据用户管理
     */
    @RequiresPermissions("auto_service:nasUser:edit")
    @Log(title = "数据用户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HdNasUser hdNasUser)
    {
        return toAjax(hdNasUserService.updateHdNasUser(hdNasUser));
    }

    /**
     * 删除数据用户管理
     */
    @RequiresPermissions("auto_service:nasUser:remove")
    @Log(title = "数据用户管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hdNasUserService.deleteHdNasUserByUserIds(ids));
    }
}
